package com.ruoyi.web.controller.qiushi.equipment;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.qiushi.domain.equipment.QiushiReport;
import com.ruoyi.qiushi.service.equipment.IQiushiReportService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报告Controller
 *
 * @author ruoyi
 * @date 2024-01-16
 */
@RestController
@RequestMapping("/qiushi/equipment/qiushreport")
public class QiushiReportController extends BaseController {
    @Autowired
    private IQiushiReportService qiushiReportService;

    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushreport:handleSend')")
    @GetMapping("/handleSend")
    public int handleSend(QiushiReport qiushiReport) {
        return qiushiReportService.handleSend(qiushiReport);
    }

    /**
     * 查询报告列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushreport:list')")
    @GetMapping("/list")
    public TableDataInfo list(QiushiReport qiushiReport) {
        startPage();
        List<QiushiReport> list = qiushiReportService.selectQiushiReportList(qiushiReport);
        return getDataTable(list);
    }

    /**
     * 导出报告列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushreport:export')")
    @Log(title = "报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QiushiReport qiushiReport) {
        List<QiushiReport> list = qiushiReportService.selectQiushiReportList(qiushiReport);
        ExcelUtil<QiushiReport> util = new ExcelUtil<QiushiReport>(QiushiReport.class);
        util.exportExcel(response, list, "报告数据");
    }

    /**
     * 获取报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushreport:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(qiushiReportService.selectQiushiReportById(id));
    }

    /**
     * 新增报告
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushreport:add')")
    @Log(title = "报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QiushiReport qiushiReport) {
        qiushiReport.setUpdateTime(new Date());
        return toAjax(qiushiReportService.insertQiushiReport(qiushiReport));
    }

    /**
     * 修改报告
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushreport:edit')")
    @Log(title = "报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QiushiReport qiushiReport) {
        return toAjax(qiushiReportService.updateQiushiReport(qiushiReport));
    }

    /**
     * 删除报告
     */
    @PreAuthorize("@ss.hasPermi('qiushi:equipment:qiushreport:remove')")
    @Log(title = "报告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(qiushiReportService.deleteQiushiReportByIds(ids));
    }
}
